package com.xyx.bloodoxygenlib.impls;

import android.util.Log;

import com.xyx.bloodoxygenlib.interfaces.IReader;

import java.io.IOException;
import java.io.InputStream;

public class InputStreamReader implements IReader {
    private InputStream is;

    public InputStreamReader(InputStream is) {
        this.is = is;
    }

    @Override // com.creative.base.Ireader
    public int read(byte[] buffer) throws IOException {
        if (this.is != null) {
            return this.is.read(buffer);
        }
        return 0;
    }

    @Override // com.creative.base.Ireader
    public void close() {
        Log.e("PC600", "InputStreamReader close");
        if (this.is != null) {
            try {
                this.is.close();
                this.is = null;
            } catch (IOException e) {
                Log.e("PC600", "InputStreamReader close error:" + e.getMessage());
                e.printStackTrace();
            }
        }
    }

    @Override // com.creative.base.Ireader
    public void clean() {
    }

    @Override // com.creative.base.Ireader
    public int available() throws IOException {
        if (this.is != null) {
            return this.is.available();
        }
        return -1;
    }
}
